package com.yuda.operationcenter.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yuda.common.log.annotation.Log;
import com.yuda.common.log.enums.BusinessType;
import com.yuda.common.security.annotation.PreAuthorize;
import com.yuda.operationcenter.domain.OperInformationHits;
import com.yuda.operationcenter.service.IOperInformationHitsService;
import com.yuda.common.core.web.controller.BaseController;
import com.yuda.common.core.web.domain.AjaxResult;
import com.yuda.common.core.utils.poi.ExcelUtil;
import com.yuda.common.core.web.page.TableDataInfo;

/**
 * 资讯的点击量Controller
 *
 * @author wyn
 * @date 2021-04-12
 */
@RestController
@RequestMapping("/hits")
public class OperInformationHitsController extends BaseController
{
    @Autowired
    private IOperInformationHitsService operInformationHitsService;

    /**
     * 查询资讯的点击量列表
     */
    @PreAuthorize(hasPermi = "operationcenter:hits:list")
    @GetMapping("/list")
    public TableDataInfo list(OperInformationHits operInformationHits)
    {
        startPage();
        List<OperInformationHits> list = operInformationHitsService.selectOperInformationHitsList(operInformationHits);
        return getDataTable(list);
    }

    /**
     * 导出资讯的点击量列表
     */
    @PreAuthorize(hasPermi = "operationcenter:hits:export")
    @Log(title = "资讯的点击量", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, OperInformationHits operInformationHits) throws IOException
    {
        List<OperInformationHits> list = operInformationHitsService.selectOperInformationHitsList(operInformationHits);
        ExcelUtil<OperInformationHits> util = new ExcelUtil<OperInformationHits>(OperInformationHits.class);
        util.exportExcel(response, list, "hits");
    }

    /**
     * 获取资讯的点击量详细信息
     */
    @PreAuthorize(hasPermi = "operationcenter:hits:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(operInformationHitsService.selectOperInformationHitsById(id));
    }

    /**
     * 新增资讯的点击量
     */
    @PreAuthorize(hasPermi = "operationcenter:hits:add")
    @Log(title = "资讯的点击量", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OperInformationHits operInformationHits)
    {
        return toAjax(operInformationHitsService.insertOperInformationHits(operInformationHits));
    }

    /**
     * 修改资讯的点击量
     */
    @PreAuthorize(hasPermi = "operationcenter:hits:edit")
    @Log(title = "资讯的点击量", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OperInformationHits operInformationHits)
    {
        return toAjax(operInformationHitsService.updateOperInformationHits(operInformationHits));
    }

    /**
     * 删除资讯的点击量
     */
    @PreAuthorize(hasPermi = "operationcenter:hits:remove")
    @Log(title = "资讯的点击量", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(operInformationHitsService.deleteOperInformationHitsByIds(ids));
    }
}
